using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using Granite.Modeling;
using Toon.Models.Catalogs;

namespace Toon.Models.Characters
{
	public class PossessionCollection : ChangeTrackingModelCollection<Possession>
	{
		public void Add(PossessionDefinition newItem)
		{
			Add(new Possession(newItem.Name, newItem.Type, newItem.Notes));
		}

		public void AddNew()
		{
			Add(new Possession("", PossessionType.Normal));
		}


        internal IList<XElement> ToXml()
        {
            return (from p in this select p.ToXml()).ToList();
        }

        internal void FromXml(XElement source)
        {
            foreach (var node in source.Elements("Possession"))
                this.Add(new Possession(node));
        }
    }
}
